package com.why.gateway.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.reactive.CorsWebFilter;
import org.springframework.web.cors.reactive.UrlBasedCorsConfigurationSource;

/**
 * @program: why-gulimall
 * @description:
 * @author: @why
 * @create: 2021-04-26 11:22
 **/
@Configuration
public class CrossOriginConfigration {


    @Bean
    public CorsWebFilter corsWebFilter() {

//        reactive.UrlBasedCorsConfigurationSource;   注意是reactive包下面的
        UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();

        //配置各种跨域的信息
        CorsConfiguration configuration = new CorsConfiguration();
        configuration.addAllowedHeader("*");
        configuration.addAllowedMethod("*");
        configuration.addAllowedOrigin("*");
        configuration.setAllowCredentials(true);
        source.registerCorsConfiguration("/**", configuration);
        return new CorsWebFilter(source);
    }
}
